﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;

// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860

namespace Sino.CapacityCloud.Web
{
    public class loginRequest
    {
        public string email { get; set; }
        public string password { get; set; }
    }
    public class LoginResponse
    {
        public string Error { get; set; }
        public LoginResponses Response { get; set; }
    }
    public class LoginResponses
    {
        public string HeadImage { get; set; }
        public string IMToken { get; set; }
        public string PhoneNumber { get; set; }
        public double Point { get; set; }
        public int RealNameState { get; set; }
        public string Token { get; set; }
        public DateTime TokenExpirationDate { get; set; }
        public string UserId { get; set; }
        public string UserName { get; set; }
    }
    
    public class logoffsResponse
    {
        public string Error { get; set; }
        public logoffResponse Response { get; set; }
    }
    public class logoffResponse { }
    public class AccountsController : Controller
    {
        //登陆
        [HttpPost("accounts/login")]
        public IActionResult login([FromBody] loginRequest loginRequest)
        {
            if (loginRequest == null)
            {
                return BadRequest();
            }
            var response = new LoginResponse()
            {
                Error = null,
                Response = new LoginResponses()
                {
                    Token = "T2e+y1rC04gZWnXpIrPaR459wEsJNFzf",
                    TokenExpirationDate = DateTime.Now.AddDays(1),
                    UserName = "admin@site.com1",
                    UserId = "221d6d7b-1267-4925-8d30-0907aa8179a1",
                    RealNameState = 1,
                    HeadImage = null,
                    Point = 0
                    
                }

            };
            return Json(response, new Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
        }

        //注销退出
        [HttpGet("accounts/logoff")]
        public IActionResult LogOff(string token)
        {
            var response = new logoffsResponse()
            {
                Error = null,
                Response = new logoffResponse() { }
            };
            return Json(response, new Newtonsoft.Json.JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });

        }
    }
}
